<template>
    <div class="comment-reply">
      <van-nav-bar :title="`${comment.reply_count}条回复`">
        <van-icon slot="right" name="cross"
        @click="$emit('close')"
        ></van-icon>
      </van-nav-bar>

      <!-- 评论项 -->
      <comment-item
        :comment="comment"
        ></comment-item>

      <!-- 评论的评论 -->
      <van-cell title="所有回复">
      </van-cell>
      <comment-list
        :source="comment.com_id"
        type="c"
        :list="commentList"
        ></comment-list>

        <!-- 底部区域 -->
    <div class="article-bottom">
      <van-button class="comment-btn" type="default" round size="small" @click="isPostShow = true">写评论</van-button>
    </div>
    <!-- /底部区域 -->
    <!-- 弹出层 -->
    <van-popup v-model="isPostShow" position="bottom">
      <post-comment 
      @post-success="onPostSuccess"
      :target="comment.com_id"
      :article-id="articleId"></post-comment>
    </van-popup>
    <!-- 弹出层 -->
    </div>
</template>
<script>
import CommentItem from './comment-item'
import CommentList from './comment-list'
import PostComment from './post-comment'
export default {
   components:{
     CommentItem,
     CommentList,
     PostComment
   },
   props:{
     comment:{
       type:Object,
       required:true
     },
     articleId:{
       type:[Number,String,Object],
       required:true
     }
   },
   data() {
      return {
        isPostShow:false,
        commentList:[] //评论的回复列表
      }
   },
   methods: {
     onPostSuccess(comment){
        this.$toast.loading({
          message: '发布中',
          forbidClick: true // 禁止背景点击
        })
        //将评论放到列表顶部
        this.commentList.unshift(comment)
        //跟新评论总数
        this.comment.reply_count++
        //关闭弹出层
        this.isPostShow=false
     }
   }
}
</script>
<style lang="scss" scoped>
.article-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-sizing: border-box;
    height: 44px;
    border-top: 1px solid #d8d8d8;
    background-color: #fff;

    .comment-btn {
      width: 200px;
      height: 30px;
      border: 1px solid #eeeeee;
      font-size: 15px;
      line-height: 23px;
      color: #a7a7a7;
    }
}
</style>
